
using System.Web.UI.HtmlControls;
using System;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Web.UI.WebControls;
using Microsoft.VisualBasic;
using System.Collections;
using System.Web.UI;
using System.Web;


using System.IO;
using System.Text;
//using com.ddsc.database;
using DDSC.OracleADO;
using com.ddsc.common;
using SMAS;
using System.Resources;
using System.Data.OracleClient;

namespace smasb2b
{
	public class VNDW0051 : BasePage
	{
		
#region  Web Form 設計工具產生的程式碼
		
		//此為 Web Form 設計工具所需的呼叫。
		[System.Diagnostics.DebuggerStepThrough()]private void InitializeComponent()
		{
			
		}
		protected System.Web.UI.HtmlControls.HtmlImage IMG1;
		protected System.Web.UI.WebControls.Label lblBSHIPMENTS;
		protected ddscControlLibrary.SubmitButtonCtrl btnSave;
		protected ddscControlLibrary.SubmitButtonCtrl btnDel;
		protected ddscControlLibrary.SubmitButtonCtrl btnExit;
		protected System.Web.UI.HtmlControls.HtmlTable Table2;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS_HISTORY;
		protected System.Web.UI.HtmlControls.HtmlTable Table4;
		protected System.Web.UI.WebControls.Label lblPURCHASE_INFO;
		protected System.Web.UI.WebControls.Label lblPURCHASE_NO1;
		protected ddscControlLibrary.InputBoxCtrl txtPURCHASE_NO1;
		protected ddscControlLibrary.InputBoxCtrl txtPLAN_ETD;
		protected System.Web.UI.WebControls.Label lblCODE;
		protected ddscControlLibrary.InputBoxCtrl txtCODE;
		protected System.Web.UI.WebControls.Label lblENGLISH_SHORTNAME;
		protected System.Web.UI.WebControls.Label lblORDER_UNIT;
		protected ddscControlLibrary.InputBoxCtrl txtORDER_UNIT;
		protected System.Web.UI.WebControls.Label lblCOEFFICIENT1;
		protected ddscControlLibrary.InputBoxCtrl txtCOEFFICIENT;
		protected System.Web.UI.WebControls.Label lblORDER_QTY;
		protected ddscControlLibrary.InputBoxCtrl txtORDER_QTY;
		protected System.Web.UI.WebControls.Label lblCURRENCY_TYPE;
		protected ddscControlLibrary.InputBoxCtrl txtCURRENCY_TYPE;
		protected System.Web.UI.WebControls.Label lblORDER_UNIT_PRICE;
		protected ddscControlLibrary.InputBoxCtrl txtORDER_UNIT_PRICE;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS_DATE;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS_SEQ;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS_QTY;
		protected System.Web.UI.WebControls.Label lblUPD_DATE;
		protected System.Web.UI.HtmlControls.HtmlTable table3;
		protected ddscControlLibrary.InputBoxCtrl Inputboxctrl1;
		protected ddscControlLibrary.InputBoxCtrl Inputboxctrl2;
		protected ddscControlLibrary.InputBoxCtrl Inputboxctrl3;
		protected ddscControlLibrary.InputBoxCtrl Inputboxctrl4;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS_DATE1;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS_QTY1;
		protected ddscControlLibrary.InputBoxCtrl txtSHIPMENTS_QTY;
		protected ddscControlLibrary.DateCtrl txtSHIPMENTS_DATE;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS;
		protected System.Web.UI.WebControls.Label lblPURCHASE_SEQ;
		protected ddscControlLibrary.InputBoxCtrl txtPURCHASE_SEQ;
		protected ddscControlLibrary.InputBoxCtrl txtENGLISH_SHORTNAME;
		protected System.Web.UI.HtmlControls.HtmlTable SHIPMENTS_HISTORY_TABLE;
		protected System.Web.UI.HtmlControls.HtmlTable DataGrid;
		protected System.Web.UI.HtmlControls.HtmlTable SHIPMENTS_TABLE;
		protected System.Web.UI.HtmlControls.HtmlInputHidden hidSHIPMENTS_SEQ;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS_QTY1_ERR;
		protected System.Web.UI.WebControls.Label lblSHIPMENTS_DATE1_ERR;
		protected System.Web.UI.WebControls.Label lblSURPLUS_OF_QTY;
		protected ddscControlLibrary.InputBoxCtrl txtSURPLUS_OF_QTY;
		
		//注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
		//請勿刪除或移動它。
		private System.Object designerPlaceholderDeclaration;
		
		private void Page_Init(System.Object sender, System.EventArgs e)
		{
			//CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
			//請勿使用程式碼編輯器進行修改。
			InitializeComponent();
		}
		
#endregion
		
		private void Page_Load(System.Object sender, System.EventArgs e)
		{
			//在這裡放置使用者程式碼以初始化網頁
			// 載入權限資料 (從 session 中取得)
			this.btnSave.Click+=btnSAVE_Click;
            this.btnDel.Click += btnDEL_Click;
			try
			{
				
				if (!Page.IsPostBack)
				{
					DataBase DataBase = new DataBase();
					DataSet ds = default(DataSet);
                    dbAccess dba = new dbAccess();
                    ArrayList m_arrParam = new ArrayList();
					string SelectCommand = "";
					string szPUR_PURCHASE_NO = Page.Request["PURCHASE_NO"];
					string szPUR_PURCHASE_SEQ = Page.Request["PURCHASE_SEQ"];
					string szCODE = Page.Request["CODE3"];
					VENDOR LoginUser = GetLoginUser();
					string szVENDOR_NO = LoginUser.VENDOR_NO;
					
					
					//至db 查詢正在修改的這一筆
					
					//訂單資訊
                    //Tony : 1.修改SQL語法使用參數，不組字串
					//SelectCommand = string.Format(
                    //    "SELECT A.*,B.ENGLISH_SHORTNAME FROM (select M.PURCHASE_NO,D.PURCHASE_SEQ,D.CODE,D.ORDER_UNIT,D.COEFFICIENT, D.ORDER_QTY, M.CURRENCY_TYPE, D.ORDER_UNIT_PRICE From PUR_PURCHASE_MASTER M ,PUR_PURCHASE_DETAILS D WHERE M.PURCHASE_NO=D.PURCHASE_NO(+)) A ,BAS_MATERIAL B WHERE A.CODE=B.CODE(+) AND A.PURCHASE_NO=\'{0}\' AND A.PURCHASE_SEQ=\'{1}\' AND A.CODE=\'{2}\' ", szPUR_PURCHASE_NO, szPUR_PURCHASE_SEQ, szCODE);
                    SelectCommand = "SELECT A.*,B.ENGLISH_SHORTNAME FROM (select M.PURCHASE_NO,D.PURCHASE_SEQ,D.CODE,D.ORDER_UNIT,D.COEFFICIENT, D.ORDER_QTY, M.CURRENCY_TYPE, D.ORDER_UNIT_PRICE From PUR_PURCHASE_MASTER M ,PUR_PURCHASE_DETAILS D WHERE M.PURCHASE_NO=D.PURCHASE_NO(+)) A ,BAS_MATERIAL B WHERE A.CODE=B.CODE(+) AND A.PURCHASE_NO=:szPUR_PURCHASE_NO AND A.PURCHASE_SEQ=:szPUR_PURCHASE_SEQ AND A.CODE=:szCODE ";
                    //Tony : 2.設定動態參數物件
                    m_arrParam.Add(dba.GetOracleParam(":szPUR_PURCHASE_NO", szPUR_PURCHASE_NO));
                    m_arrParam.Add(dba.GetOracleParam(":szPUR_PURCHASE_SEQ", szPUR_PURCHASE_SEQ));
                    m_arrParam.Add(dba.GetOracleParam(":szCODE", szCODE));
                    //Tony : 3.修改執行方法Overload
                    //ds = DataBase.Query_CLASS(SelectCommand, "PUR_PURCHASE_MASTER");
                    //ds = dba.runExecuteQuery("PUR_PURCHASE_MASTER", SelectCommand, m_arrParam);
                    //Ken20140715
                    ds = DataBase.Query_CLASS(SelectCommand, "PUR_PURCHASE_MASTER", m_arrParam);
                   
					
					this.txtPURCHASE_NO1.EnableView = true;
					this.txtPURCHASE_SEQ.EnableView = true;
					this.txtCODE.EnableView = true;
					this.txtENGLISH_SHORTNAME.EnableView = true;
					this.txtORDER_UNIT.EnableView = true;
					this.txtCOEFFICIENT.EnableView = true;
					this.txtORDER_QTY.EnableView = true;
					this.txtCURRENCY_TYPE.EnableView = true;
					this.txtORDER_UNIT_PRICE.EnableView = true;
					
					if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
					{
						this.txtPURCHASE_NO1.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["PURCHASE_NO"].ToString());
						this.txtPURCHASE_SEQ.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["PURCHASE_SEQ"].ToString());
						this.txtCODE.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["CODE"].ToString());
						this.txtENGLISH_SHORTNAME.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["ENGLISH_SHORTNAME"].ToString());
						this.txtORDER_UNIT.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["ORDER_UNIT"].ToString());
						this.txtCOEFFICIENT.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["COEFFICIENT"].ToString());
						this.txtORDER_QTY.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["ORDER_QTY"].ToString());
						this.txtCURRENCY_TYPE.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["CURRENCY_TYPE"].ToString());
						this.txtORDER_UNIT_PRICE.Text = System.Convert.ToString(ds.Tables["PUR_PURCHASE_MASTER"].Rows[0]["ORDER_UNIT_PRICE"].ToString());
						//出貨記錄
						this.txtSURPLUS_OF_QTY.Text = (dynamic)this.txtORDER_QTY.Text;
                        //Tony : 1.修改SQL語法使用參數，不組字串
						//SelectCommand = string.Format("SELECT * FROM B2B_SHIPMENTS WHERE PURCHASE_NO=\'{0}\' AND PURCHASE_SEQ=\'{1}\' AND CODE=\'{2}\' ", szPUR_PURCHASE_NO, szPUR_PURCHASE_SEQ, szCODE);
                        SelectCommand = "SELECT * FROM B2B_SHIPMENTS WHERE PURCHASE_NO=:szPUR_PURCHASE_NO AND PURCHASE_SEQ=:szPUR_PURCHASE_SEQ AND CODE=:szCODE ";
                        //Tony : 2.設定動態參數物件
                        m_arrParam.Clear();
                        m_arrParam.Add(dba.GetOracleParam(":szPUR_PURCHASE_NO", szPUR_PURCHASE_NO));
                        m_arrParam.Add(dba.GetOracleParam(":szPUR_PURCHASE_SEQ", szPUR_PURCHASE_SEQ));
                        m_arrParam.Add(dba.GetOracleParam(":szCODE", szCODE));
                        //Tony : 該方法新增了傳入ArrayList參數
                        //DataGrid_Bind_SHIPMENTS_TABLE(SelectCommand);
                        DataGrid_Bind_SHIPMENTS_TABLE(SelectCommand,m_arrParam);
						if ((string) (Page.Request["action_type"].ToUpper()) == "ADD_SHIPMENT")
						{
							this.btnDel.Visible = false;
						}
						else if ((string) (Page.Request["action_type"].ToUpper()) == "FIND")
						{
							this.btnDel.Visible = false;
							this.btnSave.Visible = false;
							SHIPMENTS_TABLE.Visible = false;
						}
						else if ((string) (Page.Request["action_type"].ToUpper()) == "DEL_SHIPMENT")
						{
							txtSHIPMENTS_DATE.EnableView = true;
							txtSHIPMENTS_QTY.EnableView = true;
							txtSURPLUS_OF_QTY.Visible = false;
							lblSURPLUS_OF_QTY.Visible = false;
							this.btnSave.Visible = false;
							if (SHIPMENTS_HISTORY_TABLE.Visible)
							{
								this.btnDel.Visible = true;
								SHIPMENTS_TABLE.Visible = true;
							}
							else
							{
								this.btnDel.Visible = false;
								SHIPMENTS_TABLE.Visible = false;
							}
						}
						else
						{
						}
						
					}
					else
					{
						showException("對不起! 此筆資料，已被刪除");
					}
					
				}
			}
			catch (Exception ex)
			{
				showException(ex.Message);
			}
		}
		
		private void btnSAVE_Click(System.Object sender, System.EventArgs e)
		{
			try
			{
				addSHIPMENTS();
			}
			catch (Exception ex)
			{
				showException(ex.Message);
			}
			
		}
		
		private void btnDEL_Click(System.Object sender, System.EventArgs e)
		{
			try
			{
				delSHIPMENTS();
			}
			catch (Exception ex)
			{
				showException(ex.Message);
			}
		}
		
		private void delSHIPMENTS()
		{
			// 設定傳送的 DataSet 物件
            //Tony:use common
            //ddscDataSet ddscDs = new ddscDataSet();
            com.ddsc.common.ddscDataSet ddscDs = new com.ddsc.common.ddscDataSet();
					
			VENDOR LoginUser = GetLoginUser();
			
			// 宣告回傳DataSet
			DataSet dsResult = new DataSet();
			try
			{
				//基本資料
                //Tony:use common
				//ddscDataTable ddscDt = ddscDs.createDataTable("B2B_SHIPMENTS");
                com.ddsc.common.ddscDataTable ddscDt = ddscDs.createDataTable("B2B_SHIPMENTS");
				// 新增Row至ddscDt
				ddscDt.addNewRow();
				// 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
				ddscDt.setColumnValue("action", "string", "upd");
				ddscDt.setColumnValue("PURCHASE_NO", "string", txtPURCHASE_NO1.Text.Trim());
				ddscDt.setColumnValue("PURCHASE_SEQ", "string", txtPURCHASE_SEQ.Text.Trim());
				ddscDt.setColumnValue("CODE", "string", txtCODE.Text.Trim());
				ddscDt.setColumnValue("SHIPMENTS_SEQ", "string", "1");
				ddscDt.setColumnValue("SHIPMENTS_SEQ", "string", hidSHIPMENTS_SEQ.Value);
				
				
				ddscDt.setColumnValue("status", "string", "0");
				ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
				ddscDt.setColumnValue("upd_date", "string", SystemDate);
				ddscDt.setColumnValue("upd_time", "string", SystemTime);
				ddscDt.setWhereValue("PURCHASE_NO", txtPURCHASE_NO1.Text.Trim());
				ddscDt.setWhereValue("PURCHASE_SEQ", txtPURCHASE_SEQ.Text.Trim());
				ddscDt.setWhereValue("CODE", txtCODE.Text.Trim());
				ddscDt.setWhereValue("SHIPMENTS_SEQ", hidSHIPMENTS_SEQ.Value);
				
				ddscDt.addNewRow();
				ddscDt.setColumnValue("action", "string", "del");
				ddscDt.setColumnValue("PURCHASE_NO", "string", txtPURCHASE_NO1.Text.Trim());
				ddscDt.setColumnValue("PURCHASE_SEQ", "string", txtPURCHASE_SEQ.Text.Trim());
				ddscDt.setColumnValue("CODE", "string", txtCODE.Text.Trim());
				ddscDt.setColumnValue("SHIPMENTS_SEQ", "string", hidSHIPMENTS_SEQ.Value);
				
				ddscDt.setWhereValue("PURCHASE_NO", txtPURCHASE_NO1.Text.Trim());
				ddscDt.setWhereValue("PURCHASE_SEQ", txtPURCHASE_SEQ.Text.Trim());
				ddscDt.setWhereValue("CODE", txtCODE.Text.Trim());
				ddscDt.setWhereValue("SHIPMENTS_SEQ", hidSHIPMENTS_SEQ.Value);
				ddscDs.addDataTable(ddscDt);
				
				// 執行新增method
				DataBase DataBase = new DataBase();
				dsResult = DataBase.Addition(ddscDs, "", (System.Array) null, (System.Array) null);
				// 寫入script至client端
				regScript(dsResult, "del");
			}
			catch (Exception ex)
			{
				showException(ex.Message);
			}
			finally
			{
			}
			
		}
		
		private void addSHIPMENTS()
		{
			// 設定傳送的 DataSet 物件
            //Tony:USE COMMON
			//ddscDataSet ddscDs = new ddscDataSet();
            com.ddsc.common.ddscDataSet ddscDs = new com.ddsc.common.ddscDataSet();

			
			VENDOR LoginUser = GetLoginUser();
			
			// 宣告回傳DataSet
			DataSet dsResult = new DataSet();
			try
			{
				//基本資料
                //Tony:USE COMMON
				//ddscDataTable ddscDt = ddscDs.createDataTable("B2B_SHIPMENTS");
                com.ddsc.common.ddscDataTable ddscDt = ddscDs.createDataTable("B2B_SHIPMENTS");
				// 新增Row至ddscDt
				ddscDt.addNewRow();
				// 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
				ddscDt.setColumnValue("action", "string", "add");
				ddscDt.setColumnValue("PURCHASE_NO", "string", txtPURCHASE_NO1.Text.Trim());
				ddscDt.setColumnValue("PURCHASE_SEQ", "string", txtPURCHASE_SEQ.Text.Trim());
				ddscDt.setColumnValue("CODE", "string", txtCODE.Text.Trim());
				if (hidSHIPMENTS_SEQ.Value == "")
				{
					ddscDt.setColumnValue("SHIPMENTS_SEQ", "string", "1");
				}
				else
				{
					ddscDt.setColumnValue("SHIPMENTS_SEQ", "string", System.Convert.ToString(System.Convert.ToInt32(hidSHIPMENTS_SEQ.Value) + 1));
				}
				ddscDt.setColumnValue("ADMONISH_FLAG", "string", "1");
				ddscDt.setColumnValue("SHIPMENTS_DATE", "string", txtSHIPMENTS_DATE.Text.Trim());
				ddscDt.setColumnValue("SHIPMENTS_QTY", "string", txtSHIPMENTS_QTY.Text.Trim());
				
				
				ddscDt.setColumnValue("status", "string", "1");
				ddscDt.setColumnValue("crt_id", "string", LoginUser.VENDOR_NO);
				ddscDt.setColumnValue("crt_date", "string", SystemDate);
				ddscDt.setColumnValue("crt_time", "string", SystemTime);
				ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
				ddscDt.setColumnValue("upd_date", "string", SystemDate);
				ddscDt.setColumnValue("upd_time", "string", SystemTime);
				ddscDt.setWhereValue("PURCHASE_NO", txtPURCHASE_NO1.Text.Trim());
				ddscDt.setWhereValue("PURCHASE_SEQ", txtPURCHASE_SEQ.Text.Trim());
				ddscDt.setWhereValue("CODE", txtCODE.Text.Trim());
				ddscDt.setWhereValue("SHIPMENTS_SEQ", hidSHIPMENTS_SEQ.Value);
				ddscDs.addDataTable(ddscDt);
				
				// 執行新增method
				DataBase DataBase = new DataBase();
                dbAccess dba = new dbAccess();
                ArrayList m_arrParam = new ArrayList();
				dsResult = DataBase.Addition(ddscDs, "", (System.Array) null, (System.Array) null);
				// 寫入script至client端
				regScript(dsResult, "add");
                //Tony : 1.修改SQL語法使用參數，不組字串
				//string SelectCommand = string.Format("SELECT * FROM B2B_SHIPMENTS WHERE PURCHASE_NO=\'{0}\' AND PURCHASE_SEQ=\'{1}\' AND CODE=\'{2}\' ", txtPURCHASE_NO1.Text, txtPURCHASE_SEQ.Text, txtCODE.Text);
                string SelectCommand = "SELECT * FROM B2B_SHIPMENTS WHERE PURCHASE_NO=:txtPURCHASE_NO1 AND PURCHASE_SEQ=:txtPURCHASE_SEQ AND CODE=:txtCODE ";
                //Tony : 2.設定動態參數物件
                m_arrParam.Add(dba.GetOracleParam(":txtPURCHASE_NO1", txtPURCHASE_NO1.Text));
                m_arrParam.Add(dba.GetOracleParam(":txtPURCHASE_SEQ", txtPURCHASE_SEQ.Text));
                m_arrParam.Add(dba.GetOracleParam(":txtCODE", txtCODE.Text)); 
                //Tony:該方法新增了傳入ArrayList參數
                //DataGrid_Bind_SHIPMENTS_TABLE(SelectCommand);
                DataGrid_Bind_SHIPMENTS_TABLE(SelectCommand,m_arrParam);
			}
			catch (Exception ex)
			{
				showException(ex.Message);
			}
			finally
			{
			}
		}

        //Tony:新增傳入參數ArrayList ArrParam
        private void DataGrid_Bind_SHIPMENTS_TABLE(string SelectCommand,ArrayList ArrParam)	
		//private void DataGrid_Bind_SHIPMENTS_TABLE(string SelectCommand)
		{
			DataBase DataBase = new DataBase();
			DataSet ds = default(DataSet);
            dbAccess dba = new dbAccess();
            //Tony:3.修改執行方法Overload
			//ds = DataBase.Query_CLASS(SelectCommand, "B2B_SHIPMENTS");
            //ds = dba.runExecuteQuery("B2B_SHIPMENTS", SelectCommand, ArrParam);
			//Ken20140715
            ds = DataBase.Query_CLASS(SelectCommand, "B2B_SHIPMENTS", ArrParam);
			if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
			{
				SHIPMENTS_HISTORY_TABLE.Visible = true;
				HtmlTableRow tr = (HtmlTableRow) (DataGrid.FindControl("DataGrid_head"));
				DataGrid_Bind_VNDW0051(SHIPMENTS_HISTORY_TABLE, ds.Tables["B2B_SHIPMENTS"]);
			}
			else
			{
				SHIPMENTS_HISTORY_TABLE.Visible = false;
			}
		}
		
		public void DataGrid_Bind_VNDW0051(HtmlTable DataGrid, DataTable DataSource)
		{
			int ORDER_QTY = 0;
			HtmlTableRow tr = (HtmlTableRow) (DataGrid.FindControl("DataGrid_head"));
			int i = 0;
			int j = 0;
			int k;
			string Url;
			string className = "";
			ResourceManager rm = GetResourceManager();
			try
			{
				for (i = 0; i <= DataSource.Rows.Count - 1; i++)
				{
					HtmlTableRow htr = new HtmlTableRow();
					if (i % 2 == 0)
					{
						className = "evenRow";
					}
					else
					{
						className = "oddRow";
					}
					htr.Attributes.Add("class", className);
					DataGrid.Rows.Add(htr);
					for (j = 0; j <= tr.Cells.Count - 1; j++)
					{
						HtmlTableCell hd = new HtmlTableCell();
						switch (tr.Cells[j].Attributes["class"].ToLower())
						{
							case "tdtitle":
								hd.Width = tr.Cells[j].Width;
								hd.Align = "center";
								hd.Attributes.Add("class", "detail");
								hd.InnerText = System.Convert.ToString(DataSource.Rows[i][tr.Cells[j].Controls[1].ID.Replace("lbl", "")].ToString());
								break;
							case "tdtitle-right":
								hd.Width = tr.Cells[j].Width;
								hd.Align = "right";
								hd.Attributes.Add("class", "detail");
								hd.InnerText = System.Convert.ToString(DataSource.Rows[i][tr.Cells[j].Controls[1].ID.Replace("lbl", "")].ToString());
								break;
								
							default:
								hd.Width = tr.Cells[j].Width;
								hd.InnerText = rm.GetString(tr.Cells[j].ID);
								break;
						}
						DataGrid.Rows[DataGrid.Rows.Count - 1].Cells.Add(hd);
						
					}
					//顯示最新一筆
					if (Page.Request["action_type"].ToUpper() == "DEL_SHIPMENT")
					{
						if (i == DataSource.Rows.Count - 1)
						{
							this.txtSHIPMENTS_DATE.Text = System.Convert.ToString(DataSource.Rows[i]["SHIPMENTS_DATE"].ToString());
							this.txtSHIPMENTS_QTY.Text = System.Convert.ToString(DataSource.Rows[i]["SHIPMENTS_QTY"].ToString());
							hidSHIPMENTS_SEQ.Value = System.Convert.ToString(DataSource.Rows[i]["SHIPMENTS_SEQ"].ToString());
						}
					}
					else
					{
						hidSHIPMENTS_SEQ.Value = System.Convert.ToString(DataSource.Rows[i]["SHIPMENTS_SEQ"].ToString());
					}
					ORDER_QTY = ORDER_QTY + (System.Convert.ToInt32(DataSource.Rows[i]["SHIPMENTS_QTY"]));
				}
				txtSURPLUS_OF_QTY.Text = System.Convert.ToString((System.Convert.ToInt32(txtORDER_QTY.Text) ) - ORDER_QTY);
				if (Page.Request["action_type"].ToUpper() != "DEL_SHIPMENT")
				{
                    this.txtSHIPMENTS_QTY.Text = (dynamic)txtSURPLUS_OF_QTY.Text;
				}
				
			}
			catch (Exception ex)
			{
				throw (ex);
			}
			
			
		}
		
		
	}
	
}
